<?php

require_once '../../bbs/include/common.inc.php';
require_once '../../classes/include.php';

if(!empty($_POST['add'])){

	$id = $_POST["id"];
	
	if($id != ""){
		$title			= $_POST["title"];
		$describes		= $_POST["describes"];
		$sort			= $_POST["sort"];
		$need_scores	= $_POST["need_scores"];
		$deduct_scores	= $_POST["deduct_scores"];
		//$datetime	= $_POST["datetime"];
		
		$content	= htmlspecialchars( stripslashes( $_POST['editor1'] ) );
		$content	= str_replace("'", "''", $content);
		//$datetime	= str_replace("'", "''", $datetime);
		
		$sql = "update video set title='".$title."', sort='".$sort."', need_scores='".$need_scores."', deduct_scores='".$deduct_scores."' where id = '".$id."'";
		$query = $db->query($sql);
		
		echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />";
		echo "<script>";
		echo "alert('修改成功!');";
		echo "location.href='list.php';";
		echo "</script>";
		exit;
	}
	exit;
}

$id = intval($_GET["id"]);
$sql = "select * from video where id = '".$id."'";
$query = $db->query($sql);
$rs = $db->fetch_array($query);

$id				= $rs["id"];
$title			= $rs["title"];
$describes		= $rs["describes"];
$sort 			= $rs["sort"];
$need_scores	= $rs["need_scores"];
$deduct_scores	= $rs["deduct_scores"];

?>
<html><head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../ckeditor.js"></script>
<link rel="stylesheet" href="../../bbs/images/admincp/admincp.css" type="text/css" media="all" /> 
<script type="text/javascript">
<!--
function ChangeLanguage( languageCode )
{
	window.location.href = window.location.pathname + "?" + languageCode ;
}

function Check(frm)
{
	if(frm.title.value == ""){
		alert("请填写视频标题!");
		frm.title.focus();
		return false;
	}
	if(isNaN(frm.need_scores.value)){
		alert("所需积分填写有误!");
		frm.need_scores.focus();
		return false;
	}
	
	if(isNaN(frm.deduct_scores.value)){
		alert("扣除积分填写有误!");
		frm.deduct_scores.focus();
		return false;
	}
	return true;
}
//-->
</script>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<form action="edit.php" method="post" onsubmit="return Check(this)">
  <table cellspacing=1 cellpadding=3 width="100%" align=center bgcolor="#CBDFF3" border=0>
    <tr class="tableheader"> 
      <td colspan="2">&nbsp;&nbsp;修改视频</td>
    </tr>
    <tr class="tablecontent"> 
      <td width="100" align="left">&nbsp;&nbsp;视频标题:</td>
      <td>
        <input type="text" name="title" maxlength="255" class="FormText" size="100" value="<?php echo $title?>">
        <input type="hidden" name="id" value="<?php echo $id?>">
      </td>
    </tr>
    <tr class="tablecontent"> 
      <td width="100" align="left">&nbsp;&nbsp;所属分类:</td>
      <td>
        <select name="sort">
        	<?php
        	//得到视频分类
			$vsql = "select * from topic_type where fup = 0 order by fid desc";
			$topic_type_query = $db->query($vsql);
			
        	while($video_menu_info = $db->fetch_array($topic_type_query)) {
        		if($sort == $video_menu_info["fid"])
        		{
        			echo "<option value=".$video_menu_info["fid"]." selected>".$video_menu_info['name']."</option>";
        		}
        		else
        		{
        			echo "<option value=".$video_menu_info["fid"].">".$video_menu_info['name']."</option>";
        		}
        		
        		/*
        		$fid = $video_menu_info['fid'];
        		if($fid != 0)
        		{
        			$sql = "select * from topic_type where fup = '".$fid."' order by fid desc";
					$topic_info = $db->query($sql);
					
					while($video_menu_infos = $db->fetch_array($topic_info)) {
						echo "<option value=".$video_menu_infos["fid"].">&nbsp;&nbsp;&nbsp;&nbsp;".$video_menu_infos['name']."</option>";
					}
        		}
				*/
			}
			?>
        </select>
      </td>
    </tr>
    <!-- <tr class="tablecontent"> 
      <td width="100" align="left">&nbsp;&nbsp;新闻日期:</td>
      <td>
        <input type="text" name="datetime" maxlength="50" class="FormText" size="100" value="<?php echo $datetime?>">
      </td>
    </tr> -->
     <tr class="tablecontent"> 
      <td width="100" align="left">&nbsp;&nbsp;描&nbsp;&nbsp;&nbsp;&nbsp;述:</td>
      <td>
        <textarea name='describes'><?php echo $describes?></textarea>
      </td>
    </tr>
    <tr class="tablecontent"> 
      <td width="100" align="left">&nbsp;&nbsp;所需积分:</td>
      <td>
        <input type="text" name="need_scores" class="FormText" value="<?php echo $need_scores?>">
      </td>
    </tr>
    <tr class="tablecontent"> 
      <td width="100" align="left">&nbsp;&nbsp;扣除积分:</td>
      <td>
        <input type="text" name="deduct_scores" class="FormText" value="<?php echo $deduct_scores?>">
      </td>
    </tr>

  </table>
  <BR>
  <table cellspacing=1 cellpadding=3 width="95%" align=center bgcolor="#FFFFFF" border=0>
    <tr> 
      <td colspan="2" align="center"> 
        <input type="submit" id="add_button" name="add" value="修改">
        <input type="button" value="返回" onclick="javascript:location.href='./list.php';">
      </td>
    </tr>
  </table>
</form>
</body>
</html>